// 04myCenter/04wasteOrder/01wasteOrderEvaluate/wasteOrderEvaluate.js
var co = require('../../../resource/js/common.js')
var app = getApp()
var _this, _data, _opt
Page({

   /**
    * 页面的初始数据
    */
   data: {
      flag: 0,
      noteMaxLen: 300, // 最多放多少字
      info: "",
      noteNowLen: 0, //备注当前字数
      // evaluateContent: '', //评价内容

   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
      _this = this
      _data = this.data
      _opt = options
      console.log('_opt', _opt)

   },

   // 监听字数
   bindTextAreaChange: function (e) {
      var that = this
      var value = e.detail.value,
         len = parseInt(value.length);
      if (len > that.data.noteMaxLen) return;
      that.setData({
         info: value,
         noteNowLen: len
      })
   },
   //评分
   changeColor1: function () {
      var that = this;
      that.setData({
         flag: 1
      });
   },
   changeColor2: function () {
      var that = this;
      that.setData({
         flag: 2
      });
   },
   changeColor3: function () {
      var that = this;
      that.setData({
         flag: 3
      });
   },
   changeColor4: function () {
      var that = this;
      that.setData({
         flag: 4
      });
   },
   changeColor5: function () {
      var that = this;
      that.setData({
         flag: 5
      });
   },
   // 提交清空当前值
   bindSubmit: function () {
      var that = this;
      var userInfo = app.Data.userInfo
      var url = 'comment/Comment/SubmitComment'
      var param = {
         Order_ID: _opt.orderID,
         User_ID: userInfo.User_ID,
         Comment_Star: _data.flag,
         Comment_Content: _data.info,
         Reclaim_User_ID: _opt.recID,
         Comment_Images: '',
      }
      if (co.empty(_data.flag)){
         _this.showMessage('请选择星级评分')
      } else if (co.empty(_data.info)){
         _this.showMessage('请填写评价详情')
      }else{
         co.getJyhsApi(url, param, function (res) {
            if (res.code == 0) {
               if (res.code == 0) {
                  _this.showMessage('评价成功')
                  _this.evaluateOrder()
                  setTimeout(function () {
                     var pages = getCurrentPages(),
                        prevPage = pages[pages.length - 2];
                     prevPage.setData({
                        alter: "123"
                     })
                     wx.navigateBack({})
                  }, 1000)
               }
            } else {
               _this.showMessage('评价失败')
            }
         })

      }
      
     
      // wx.showToast({
      //    title: '发布成功',
      //    icon: 'success',
      //    duration: 1500,
      //    mask: false,
      //    success: function() {
      //       that.setData({
      //          info: '',
      //          noteNowLen: 0,
      //          flag: 0
      //       })
      //    }
      // })
   },

   //修改订单状态为已评价
   evaluateOrder: function () {
      var url = 'order/Order/updateOrderStatue'
      co.getJyhsApi(url, {
         Order_Status: 3,
         Order_ID: _opt.orderID
      }, function (res) {
         if (res.code == 0) {
            console.log(res.msg)
         } else {
            console.log(res.msg)
         }
      })
   },

   //显示提示信息
   showMessage: function (text) {
      var that = this
      that.setData({
         showMessage: true,
         messageContent: text
      })
      setTimeout(function () {
         that.setData({
            showMessage: true,
            messageContent: text
         })
         setTimeout(function () {
            that.setData({
               showMessage: false,
               messageContent: ''
            })
         }, 3000)
      })
   },


   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function () {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide: function () {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {

   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function () {

   }
})